package com.xls.box2023.wxshare;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;

import com.lzz.bottomencapsulation.BuildConfig;
import com.lzz.bottomencapsulation.net.RequestCallBack;
import com.lzz.bottomencapsulation.utils.TUtils;
import com.xls.box2023.mvp.BasePresenterImpl;
import com.xls.box2023.utils.SPUtils;

/**
 * MVPPlugin
 */

public class WXSharePresenter extends BasePresenterImpl<WXShareContract.View> implements WXShareContract.Presenter{
    @Override
    public void getSourceData() {
        super.getSourceData();
//        WxShareUtils.getInstance().getUserCode(new RequestCallBack<UserEntity>() {
//            @Override
//            public void onStart() {
//
//            }
//
//            @Override
//            public void onStop() {
//            }
//
//            @Override
//            public void onRequestSuccess(UserEntity requestData) {
//                if (getView()==null||context==null||requestData==null)return;
//                if (TextUtils.isEmpty(requestData.getWxcodeHost())) return;
//                LUtils.e("weixin",requestData.getWxcodeHost());
//                mView.showBitmapCode(requestData.getWxcodeHost(),requestData.getUnionId());
//            }
//
//            @Override
//            public void onRequestfail(String errno, String errmsg) {
//
//            }
//        });
                WxShareUtils.getInstance().getUserCode(new RequestCallBack<String>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onStop() {
            }

            @Override
            public void onRequestSuccess(String requestData) {
                if (getView()==null||context==null||requestData==null)return;
                if (TextUtils.isEmpty(requestData)) return;
                mView.showBitmapCode(requestData,"");
            }

            @Override
            public void onRequestfail(String errno, String errmsg) {
                TUtils.showShort(context,errmsg);
            }
        }, BuildConfig.APKNAME, SPUtils.getunId());
    }

    public static Bitmap getCacheBitmapFromView(View view) {
        final boolean drawingCacheEnabled = true;
        view.setDrawingCacheEnabled(drawingCacheEnabled);
        //设置背景色  //view.setBackgroundColor(CommonUtils.getContext().getResources().getColor(R.color.half_white));
        view.buildDrawingCache(drawingCacheEnabled);
        final Bitmap drawingCache = view.getDrawingCache();
        Bitmap bitmap;
        if (drawingCache != null) {
            bitmap = Bitmap.createBitmap(drawingCache);
            view.setDrawingCacheEnabled(false);
        } else {
            bitmap = null;
        }
        return bitmap;
    }
}
